package org.vineatoum.view.utils;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class JPanelWrapperOkCancel extends JPanelWrapper{
	private static final long serialVersionUID = -4366553155874993832L;
	
	protected JPanel buttonPanel;
	
	protected JButton btnValidate;
	protected JButton btnCancel;
	private JPanelWrapped wrapped;
	public JPanelWrapperOkCancel(JPanelWrapped _mainPanel) {
		super(_mainPanel);
		wrapped =_mainPanel;
		//wrapped = new JPanelWrappedOkCancel(_mainPanel);
		// TODO Auto-generated constructor stub
		buttonPanel = new JPanel();
		add(buttonPanel, BorderLayout.SOUTH);
		
		btnValidate = new JButton("Valider");
		btnValidate.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent arg0) {
				
			}
			
			@Override
			public void mousePressed(MouseEvent arg0) {
				
			}
			
			@Override
			public void mouseExited(MouseEvent arg0) {
				
			}
			
			@Override
			public void mouseEntered(MouseEvent arg0) {
				
			}
			
			@Override
			public void mouseClicked(MouseEvent e) {
				onValidateClick(e);
			}
		});
		buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5));
		buttonPanel.add(btnValidate);		
		btnCancel = new JButton("Annuler");
		btnCancel.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent arg0) {
				
			}
			
			@Override
			public void mousePressed(MouseEvent arg0) {
				
			}
			
			@Override
			public void mouseExited(MouseEvent arg0) {
				
			}
			
			@Override
			public void mouseEntered(MouseEvent arg0) {
				
			}
			
			@Override
			public void mouseClicked(MouseEvent e) {
				onCancelClick(e);
			}
		});
		buttonPanel.add(btnCancel);
		
	}
	
	protected void onValidateClick(MouseEvent e) {
		//JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "OK Clicked. Function not overrided.");
		wrapped.doWhenWrapperOkClick();
	}
	
	protected void onCancelClick(MouseEvent e) {
		wrapped.doWhenWrapperCancelClick();
		getParent().remove(this);
		
	}

}
